package principles.P02_接口隔离原则_InterfaceSegregation;

public class P02_Improve {
    public static void main(String[] args) {
        Ai ai = new Ai();
        ai.depend1(new Bi());
        ai.depend2(new Bi());
        ai.depend3(new Bi());

        Ci ci = new Ci();
        ci.depend1(new Di());
        ci.depend4(new Di());
        ci.depend5(new Di());
    }
}

interface InterfaceI1 {
    void operation1();
}

interface InterfaceI2 {
    void operation2();
    void operation3();
}
interface InterfaceI3 {
    void operation4();
    void operation5();
}

class Bi implements InterfaceI1, InterfaceI2 {

    @Override
    public void operation1() {
        System.out.println("B operation1");
    }

    @Override
    public void operation2() {
        System.out.println("B operation2");
    }

    @Override
    public void operation3() {
        System.out.println("B operation3");
    }
}

class Di implements InterfaceI1, InterfaceI3 {

    @Override
    public void operation1() {
        System.out.println("D operation1");
    }

    @Override
    public void operation4() {
        System.out.println("D operation4");
    }

    @Override
    public void operation5() {
        System.out.println("D operation5");
    }
}

class Ai {
    public void depend1(InterfaceI1 interface1) {
        interface1.operation1();
    }

    public void depend2(InterfaceI2 interface1) {
        interface1.operation2();
    }

    public void depend3(InterfaceI2 interface1) {
        interface1.operation3();
    }
}

class Ci{
    public void depend1(InterfaceI1 interface1) {
        interface1.operation1();
    }

    public void depend4(InterfaceI3 interface1) {
        interface1.operation4();
    }

    public void depend5(InterfaceI3 interface1) {
        interface1.operation5();
    }
}

